﻿#include "stdafx.h"

#include "svgextrainfowidget.h"

#include <QLabel>

#include "svgcanvas.h"
#include "svgshape.h"

#include <QStackedLayout>
#include <QLineEdit>

namespace
{
	constexpr int CANVAS_INFO_WIDGET_IDX = 0;
	constexpr int LINE_INFO_WIDGET_IDX = 1;
	constexpr int TODO_WIDGET_IDX = 2;
}

SvgExtraInfoWidget::SvgExtraInfoWidget(QWidget* parent)
	: QWidget(parent)
	, lineInfoWidget(new SvgLineInfoWidget(this))
	, canvasInfoWidget(new SvgCanvasInfoWidget(this))
	, m_stackLayout(new QStackedLayout(this))
	, m_todoLabel(new QLabel(tr("TODO: not support this feature"), this))
{
	m_stackLayout->addWidget(canvasInfoWidget);
	m_stackLayout->addWidget(lineInfoWidget);

	m_stackLayout->addWidget(m_todoLabel); // 最后记得删掉

	setLayout(m_stackLayout);
}

void SvgExtraInfoWidget::ShowCanvasData(const SvgCanvas& canvas) const
{
	m_stackLayout->setCurrentIndex(CANVAS_INFO_WIDGET_IDX);
	canvasInfoWidget->UpdateData(canvas);
}

void SvgExtraInfoWidget::ShowShapesData(vector<SvgShape*>& shapes)
{
	ASSERT(!shapes.empty());
	if (shapes.size() == 1)
		shapes.front()->Accept(*this);
	else
		_ShowMultiShapeData(shapes);
}

void SvgExtraInfoWidget::_VisitLine(SvgLine& line)
{
	m_stackLayout->setCurrentIndex(LINE_INFO_WIDGET_IDX);
	lineInfoWidget->UpdateData(line);
}

void SvgExtraInfoWidget::_VisitRect(SvgRect& rect)
{
	// todo
	m_stackLayout->setCurrentIndex(TODO_WIDGET_IDX);
}

void SvgExtraInfoWidget::_VisitEllipse(SvgEllipse& ellipse)
{
	// todo
	m_stackLayout->setCurrentIndex(TODO_WIDGET_IDX);
}

void SvgExtraInfoWidget::_VisitPolygon(SvgPolygon& polygon)
{
	// todo
	m_stackLayout->setCurrentIndex(TODO_WIDGET_IDX);
}

void SvgExtraInfoWidget::_VisitText(SvgText& text)
{
	// todo
	m_stackLayout->setCurrentIndex(TODO_WIDGET_IDX);
}

void SvgExtraInfoWidget::_VisitPath(SvgPath& path)
{
	// todo
	m_stackLayout->setCurrentIndex(TODO_WIDGET_IDX);
}

void SvgExtraInfoWidget::_ShowMultiShapeData(vector<SvgShape*>& shapes)
{
	// todo
	m_stackLayout->setCurrentIndex(TODO_WIDGET_IDX);
}
